BMEN90033 · Week 10
Back
BMEN90033 · WEEK 10 · DIGITAL LOGIC BUILDING BLOCKS

From transistor pairs to digital arithmetic logic

After digitisation, signals are processed by combinational networks of two-state devices. Two complementary MOSFETs form an inverter; an inverter and a series pair form NAND; NAND alone is functionally complete. Structured NAND networks yield the four primitives that route, combine and select digital signals: adders, subtractors, multiplexers, decoders.

Use the dots or the arrow keys to advance through the slides.

cmos boolean algebra adder subtractor multiplexer decoder
01boolean primitives

Logic gates and the Boolean primitives

A bit is encoded as one of two voltage levels: low near ground for $0$, high near the supply for $1$. A gate maps its inputs to its output through a Boolean function. The eight primitives below underlie every later construction.

  • NOT. Output is the complement of the input.
  • BUF. Output equals the input; used for fan-out and signal restoration.
  • AND. Output is $1$ only when every input is $1$.
  • OR. Output is $1$ when at least one input is $1$.
  • NAND. Negation of AND. Functionally complete: any Boolean function can be built from NAND alone.
  • NOR. Negation of OR. Also functionally complete.
  • XOR. Output is $1$ when the inputs differ. Addition modulo two.
  • XNOR. Negation of XOR. Output is $1$ when the inputs agree.

Each gate is fully specified by its truth table. NAND and NOR dominate CMOS layouts because they need fewer transistors than AND or OR and remain functionally complete. Two-input expressions, with overbar denoting negation:

$Y_{\text{AND}} = A \cdot B$
$Y_{\text{OR}} = A + B$
$Y_{\text{NAND}} = \overline{A \cdot B}$
$Y_{\text{NOR}} = \overline{A + B}$
$Y_{\text{XOR}} = A \oplus B = A\bar B + \bar A B$
$Y_{\text{XNOR}} = \overline{A \oplus B}$
Symbol convention: AND is a flat-back D, OR a curved shield, NOT a triangle. A bubble at any input or output denotes negation, so NAND is AND with an output bubble and NOR is OR with one.
A B
seven gates · symbol, expression, truth row
02bjt logic

Building gates from bipolar transistors

Before CMOS, the same Boolean primitives were realised with bipolar junction transistors. An NPN device acts as a switch: drive its base above roughly $0.7\,\text{V}$ and the collector clamps near ground; hold the base low and the collector floats up to $V_{CC}$ through a pull-up resistor. Three single-stage circuits cover the universal cases.

The inverter places one transistor between $Y$ and ground, with $R_C$ tying $Y$ to $V_{CC}$. A high input saturates the transistor and pulls $Y$ low; a low input cuts it off and $R_C$ pulls $Y$ high.

NOR places two transistors in parallel between $Y$ and ground: either input being high is enough to pull $Y$ low. NAND places the same two transistors in series: both inputs must be high before the conduction path to ground is complete. The base resistors $R_A$ and $R_B$ limit base current; the collector resistor $R_C$ sets the high-state voltage and the static current draw.

$Y_{\text{NOT}} = \overline{A}$
$Y_{\text{NOR}} = \overline{A + B}$   (parallel)
$Y_{\text{NAND}} = \overline{A \cdot B}$   (series)
Resistor-transistor logic dissipates static power: while a transistor is on, current flows continuously through $R_C$ to ground. CMOS, on the next slide, eliminates this by replacing $R_C$ with a complementary transistor that is off whenever the pull-down is on.
A B
three RTL gates · NOT, NOR, NAND from NPN transistors
03cmos construction

CMOS construction of logic gates

A CMOS process places a p-channel and an n-channel MOSFET on the same substrate. PMOS conducts when its gate is low; NMOS conducts when its gate is high. Tying the two gates together, with the PMOS source at $V_{DD}$ and the NMOS source at ground, gives the inverter at the common drain.

For a low input the PMOS pulls the output to $V_{DD}$; for a high input the NMOS pulls it to ground. At every static input one device is off, so no DC current flows. Power is dissipated only during the switching transient, which is the origin of CMOS's low static power.

NAND stacks two NMOS in series to ground and two PMOS in parallel to $V_{DD}$: the output is pulled low only when both inputs are high. NOR is the dual: NMOS in parallel, PMOS in series. AND and OR are NAND and NOR followed by an inverter. XOR and memory storage cells follow the same patterns.

NAND alone, and NOR alone, are functionally complete. Fabs therefore lay down a sea of identical NAND or NOR cells and route them to realise arbitrary logic, rather than fabricate a distinct cell per operation.
input Vout = VDD
cmos inverter · PMOS pull-up, NMOS pull-down
cmos NAND · two PMOS in parallel, two NMOS in series
universality · NOT, AND, OR built from NAND only
04half, full and ripple-carry adders

Binary adders: half, full and ripple-carry

Adding two single bits $A$ and $B$ produces a sum $S$ and carry $C_{\text{out}}$. $S$ is $1$ when the inputs differ (XOR); $C_{\text{out}}$ is $1$ when both are $1$ (AND). The two-gate circuit is the half adder.

$S = A \oplus B$
$C_{\text{out}} = A \cdot B$

Multi-bit operands require each column to accept a carry-in. A full adder takes $A$, $B$, $C_{\text{in}}$ and outputs $S$ and $C_{\text{out}}$. It is built from two half adders and an OR:

$S = A \oplus B \oplus C_{\text{in}}$
$C_{\text{out}} = A \cdot B + C_{\text{in}} \cdot (A \oplus B)$

Cascading $n$ full adders, with each $C_{\text{out}}$ feeding the next $C_{\text{in}}$, gives the ripple-carry adder. The first $C_{\text{in}}$ is tied to zero. The panel toggles two 4-bit operands and shows the carry propagating across the four stages.

Propagation delay grows linearly with operand width because each stage waits on its carry-in. Carry-lookahead and carry-select adders compute the carries in parallel from group functions, trading area for speed; the output function is the same.
A B
half adder · S = A⊕B, C = A·B
full adder · two half adders + OR
4-bit ripple-carry adder · A + B
A0011
B0110
sum01001
decimal3 + 6 = 9
05two's-complement arithmetic

Subtraction by two's-complement addition

Dedicated subtractor circuits are rarely fabricated. In two's-complement representation, the negation of an $n$-bit operand $B$ is $\bar B + 1$, so

$A - B = A + \bar B + 1$

and a ripple-carry adder performs subtraction by inverting $B$ and asserting the lowest carry-in. A mode bit $M$ controls the operation: each $B_i$ passes through an XOR gate whose other input is $M$, and $M$ also drives $C_{\text{in,0}}$.

For $M = 0$ the XORs pass $B$ unchanged and $C_{\text{in,0}} = 0$, computing $A + B$. For $M = 1$ the XORs invert $B$ and $C_{\text{in,0}} = 1$, computing $A + \bar B + 1 = A - B$. The same lattice serves both; only the interpretation of the result changes.

Under two's-complement arithmetic the carry-out of the most significant stage is not the sign bit. Overflow is detected as the XOR of the carry into and out of the highest stage.

Two's complement is the only signed representation in which the unsigned addition circuit also performs signed addition unmodified. Sign-magnitude and one's-complement need a separate subtractor or end-around carry; neither is used in modern processors.
A B mode
4-bit adder/subtractor · M = 0 add, M = 1 sub
A0101
B0011
B XOR M1100
result0010
decimal5 − 3 = 2
overflowno
06data routing

Multiplexers: routing one of $2^k$ inputs

A multiplexer routes one of $2^k$ data inputs to a single output, selected by a $k$-bit code. The 2:1 mux takes $D_0$, $D_1$ and select line $S$, with

$Y = \bar S \cdot D_0 + S \cdot D_1$

An inverter forms $\bar S$; two AND gates form the products $\bar S \cdot D_0$ and $S \cdot D_1$; an OR combines them. Exactly one AND is enabled at a time, so exactly one input reaches $Y$.

A 4:1 mux uses two select lines $S_1 S_0$ with three-input ANDs, gating each $D_i$ with the matching combination of $S_1$, $S_0$ and their negations:

$Y = \bar S_1 \bar S_0 D_0 + \bar S_1 S_0 D_1 + S_1 \bar S_0 D_2 + S_1 S_0 D_3$

The inverse block is the demultiplexer: one input routed to one of $2^k$ outputs. Structurally it is a decoder whose output ANDs each take an extra data input.

In instrumentation front ends, a multiplexer shares a single ADC across many electrodes. The select code is the channel address, generated by a microcontroller or by a counter clocked at the per-channel sampling rate.
D S1S0
2:1 mux · Y = ¬S·D₀ + S·D₁
4:1 mux · two select lines, four data inputs
select code10
routed inputD₂
Y0
07address decoding

Decoders: an $n$-bit code to a one-hot output

A binary decoder maps an $n$-bit code to a one-hot bus of $2^n$ lines: exactly one line is high, corresponding to the integer represented by the input. For a 2-to-4 decoder with inputs $A_1 A_0$,

$Y_0 = \bar A_1 \bar A_0$, $Y_1 = \bar A_1 A_0$, $Y_2 = A_1 \bar A_0$, $Y_3 = A_1 A_0$

Each output is an AND of the input bits or their inverses, with the inversion pattern matching the binary form of the output index. A 3-to-8 decoder uses three-input ANDs and an extra inverter stage.

Most decoders expose an active-low enable $\bar E$. Deasserting it forces every output to zero. Enables allow hierarchical composition: a 4-to-16 decoder is built from five 2-to-4 decoders, with one feeding the enables of the others. The same scaling reaches memory address decoders with twenty or more bits.

A decoder followed by an OR-tree implements an arbitrary truth table directly: the decoder expands the $n$ inputs into all $2^n$ minterms, and the OR-tree selects those that yield a one. This underlies ROMs and the lookup-table logic of FPGAs.
A2A1A0 enable
2-to-4 decoder · four AND gates with inverter pattern
3-to-8 decoder · one-hot output bus
address101
decimal5
asserted lineY₅
08applications in instrumentation

Applications in bioinstrumentation

Adders, subtractors, multiplexers and decoders compose every datapath that processes a digitised signal. The role of each primitive in a typical instrumentation system:

Multi-channel ADC front ends

An analog multiplexer in front of a single ADC shares the converter across many electrodes. The select code, generated by a counter or by software, selects the channel for the current conversion and may also feed a decoder that drives per-channel calibration lines.

Digital filter accumulators

FIR filters compute a sum of products between past samples and fixed coefficients. Each tap product is formed by a multiplier; the running sum across taps is formed by a chain of two's-complement adders.

Address decoding in microcontrollers

A microcontroller's address bus selects between memory regions, peripheral registers and external chip-select lines through one or more decoders. High-order address bits drive the decoder; each output enables one peripheral or memory bank.

Successive-approximation register

The SAR ADC of Week 9 contains a trial-code register, a comparator, and combinational logic that updates the register from the comparator output. The update is a multiplexer: the bit either keeps its trial value or is cleared, depending on the decision.

Encoder in a flash ADC

A flash ADC produces a thermometer code from $2^n - 1$ comparators. A priority encoder, structurally a decoder run in reverse, maps this code to an $n$-bit binary output. It is the only block whose latency depends on the bit count.

Whenever a digital circuit must combine, route, select, count or compare signals, one of these four primitives sits at its centre. Implementations vary; the Boolean function does not. A NAND lattice realises every digital block on this page.
1 / 9